package com.oma.testcase;

import java.util.concurrent.TimeUnit;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;

public class Login  {

	String pw = "welcome";
	String user = "";
	
	public void login(WebDriver driver, String usename) throws Exception {
		
		if(usename == "reviewer") 
		{
			user = "reviewergc";
		}
		else if(usename == "secretary")
		{
			user = "mppandy";
		}
		else if(usename == "section")
		{
			user = "sectionhead1";
		}
		else if(usename == "unit")
		{
			user = "unithead1";
		}
		else if(usename == "director")
		{
			user = "asdelapena";
		}
		else if(usename == "president")
		{
			user = "ercortez";
		}
		else 
		{
			System.out.println("No username matched!");
		}
		
		WebElement username = driver.findElement(By.xpath("//div[@class='email']/input"));
		WebElement password = driver.findElement(By.xpath("//div[@class='pw']/input"));
		WebElement button = driver.findElement(By.xpath("//div[@class='submit']/input"));
		
		//login to admin page
		username.sendKeys(user);
		password.sendKeys(pw);
		button.click();
		driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
    
		try{
			driver.findElement(By.xpath("//a[@href='logout.html' and contains(., 'Sign out')]"));
			System.out.println("Login successful: " +usename);
		}catch(Exception e){
			System.out.println("Login failed.");
		}

    }
}
